package com.grts.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.grts.pojo.UserBean;
import com.grts.service.IUserService;


/**
 * 登陆模块
 * @author Ene
 *
 */
@Controller
@RequestMapping("/user")
public class UserController {
	@Resource
	private IUserService userservice;
	
	
	@RequestMapping("/login")
	public String login(Map<String,Object> map,UserBean user,HttpSession session){
		System.out.println(user);
		List<UserBean> userlist=userservice.queryByNameAndPwd(user);
		System.out.println(userlist.size());
		if(userlist.size()>0)
		{
			session.setAttribute("user", userlist.get(0));
			return "../index";
		}else{
			map.put("errorMsg", "用户名或密码错误");
			return "../login";
		}
		
	}
	
	@RequestMapping("/loginout")
	public String loginout(HttpSession session){
		//清除登录信息
		session.invalidate();
		return "../login";
	}
}
